import {action, observable, runInAction} from "mobx";
import {BaseResInterface, BaseResInterfaceWithData, sendGetRequest, sendPostRequest} from "../../../net";
import {defaultArr, defaultObj} from "../../../util";
import {StoreInterface, UserOutPointsInterface} from "../../../net/instance/CommenModelInstance";
import UserStoreInstance from "./index";


interface WithDraw {

}

export class WithDrawStore {

    @observable storeInfo: StoreInterface = defaultObj;
    @observable userOutPointDetails: UserOutPointsInterface[] = defaultArr;

    @action.bound
    async getStoreInfo() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<StoreInterface>>("store/getStoreInfo");
        runInAction(() => {
            this.storeInfo = data;
        })
    }

    @action.bound
    async checkWithDrawnAuthority() {
        const {code} = await sendGetRequest<BaseResInterfaceWithData<any>>("user/checkWithDrawnAuthority", {userId: UserStoreInstance.user.id});
        return code === 200;
    }

    @action.bound
    async sendWithDrawnRequest(params) {
        const {code} = await sendPostRequest<BaseResInterfaceWithData<any>>("user/sendWithDrawnRequest", {userId: UserStoreInstance.user.id, ...params});
        return code === 200;
    }

    @action.bound
    async getUserWithDrawDetails() {
        const {data} = await sendGetRequest<BaseResInterfaceWithData<UserOutPointsInterface[]>>("user/getUserWithDrawDetails", {userId: UserStoreInstance.user.id});
        runInAction(() => {
            this.userOutPointDetails = data;
        })
    }


}

const WithDrawStoreInstance = new WithDrawStore();
export default WithDrawStoreInstance